package com.welike.shibo.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author fangyu
 * @version v1.0.0
 * @since 2019-08-20 12:37
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 登录前先检查
        Object user = request.getSession().getAttribute("loginUser");
        if (user == null) {
            // 未登录
            request.setAttribute("msg", "无权限请先登录");
//            request.getRequestDispatcher("/index").forward(request, response);
            return false;
        } else {
            // 放行
            return true;
        }
        // 从header取出jwt
//        String token = request.getHeader(Constants.TOKEN_HEADER);
//        return true;
    }
}
